package com.demo.design_patterns;

/**
 * @author shenguangyang
 */
public class Singleton_E01 {
    private static volatile Singleton_E01 singleton;

    /**
     * 构造函数私有，禁止外部实例化
     */
    private Singleton_E01() {}

    public static Singleton_E01 getInstance() {
        if (singleton == null) {
            synchronized (Singleton_E01.class) {
                if (singleton == null) {
                    singleton = new Singleton_E01();
                }
            }
        }
        return singleton;
    }

    public static void main(String[] args) {
        Singleton_E01 instance = getInstance();

    }
}
